﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CapaDTO;
using CapaConexion;
using CapaNegocio;
using AppPizza.net.webservicex.www;

namespace AppPizza
{
    public partial class MantenedorRepartidor : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
          
        }

        protected void btnIngresarRep_Click(object sender, EventArgs e)
        {
            Repartidor r = new Repartidor();

            

            // Aquí usamos el webservice
            ValidateEmail emailService = new ValidateEmail();
            bool emailBueno;        
    
            // A veces el servicio tira errores, así que ponemos try/catch
            try
            {
                emailBueno = emailService.IsValidEmail(this.txtEmailRep.Text);
                if (emailBueno == true)
                {
                    r.Email = this.txtEmailRep.Text;
                }
                else
                {
                    this.lblEstado.Text = "EMAIL NO VALIDO";
                    return;

                }
            }
            catch {
                this.lblEstado.Text = "EMAIL NO VALIDO o ERROR EN EL SISTEMA";
                return;
            }


            r.Id_vehiculo = Int32.Parse(this.ddlTipoDeVehiculoRep.SelectedItem.Value);
            r.Nombre = this.txtNombreRep.Text;

            r.Id_repartidor = 1;
            try
            {
                r.Id_repartidor = Int32.Parse(ddlID.SelectedItem.Value) + 1;

            }
            catch { 
            
            }
            NegocioRepartidor nr = new NegocioRepartidor();
            Error sqlerror = nr.insertarRepartidor(r);
            Response.Redirect(Request.RawUrl);


            
        }

        protected void datasrcID_MAX_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {

        }
    }
}
